# Builder stage for building the package
FROM python:3.11-slim AS builder

# Set the working directory
WORKDIR /build

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends build-essential

# Install Python dependencies and build the wheel
RUN pip install wheel Cython

# Copy the code
COPY . /build

#use inplace that build_py will ignore py file if .so exists
#RUN python setup.py build_ext --inplace 
#RUN python setup.py build_py
RUN python setup.py bdist_wheel
#RUN pip wheel . -w dist

# Final stage for running the application
FROM python:3.11-slim

RUN apt-get update && apt-get install -y --no-install-recommends curl unzip

# Set the working directory in the container
WORKDIR /app

# Copy only the built wheel from the builder stage
COPY --from=builder /build/requirements.txt /app/

# Install requirements.txt
RUN pip install -r requirements.txt

# Copy only the built wheel from the builder stage
COPY --from=builder /build/dist/*.whl /app/
# Copy log_config.yml from source
COPY log_config.yml /app/

# Install the application
RUN pip install *.whl

# Install specific dependencies
RUN pip install "ray[client]==2.31.0" pydantic absl-py requests uvicorn

# Expose port 8080
EXPOSE 8080

# Environment variable
ENV NAME=World

# Command to run the application
CMD ["uvicorn", "app.serve:app", "--host", "0.0.0.0", "--port", "8080", "--log-config", "log_config.yml"]
